//
//  FPRegisterViewController.m
//  ForestPack
//
//  Created by jimmy on 2018/7/3.
//  Copyright © 2018年 郑洲. All rights reserved.

///  选择个人还是企业的界面

#import "FPRegisterViewController.h"
#import "FPPesonRegisViewController.h"
//#import "FPEnterpriseRegisViewController.h"
#import "EnterPriseCustomerRegistVC.h"

#import <Masonry.h>
#import "FPCertificateViewController.h"

@interface FPRegisterViewController ()

@property (nonatomic,strong)  FPRegisterSelectView * personView;
@property (nonatomic,strong)  FPRegisterSelectView * enterpriseView;

@property (nonatomic,assign)  InitRegisterType       registerType;

@end

@implementation FPRegisterViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = YES;
    
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.registerType = InitRegisterType_Personal;
    
    [self setSubViewUI];
    
}

-(void)backClick
{
    [self.navigationController popViewControllerAnimated:true];
}

-(void)sureClick
{
    switch ( self.registerType) {
        case InitRegisterType_Personal:
        {
            FPPesonRegisViewController* personVC = [[FPPesonRegisViewController alloc] init];
            personVC.registerType = InitRegisterType_Personal;
            personVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:personVC animated:true];
        }
            break;
        case InitRegisterType_Enterprise:
        {
            EnterPriseCustomerRegistVC *enterpriseRegisVC = [[EnterPriseCustomerRegistVC alloc] init];
            enterpriseRegisVC.registerType = InitRegisterType_Enterprise;
            enterpriseRegisVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:enterpriseRegisVC animated:true];
        }
            break;
        default:
            break;
    }
}

- (void)setSubViewUI
{
    UIImageView * bjImageV  = [[UIImageView alloc] initWithFrame:CGRectMake(0, -NAVIGATION_BAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)];
    bjImageV.image = [UIImage imageNamed:@"注册背景"];
    bjImageV.userInteractionEnabled = YES;
    [self.view addSubview:bjImageV];
    
    [bjImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(@0);
        make.width.height.equalTo(self.view);
    }];
    
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(13, APP_STATUSBAR_HEIGHT, 22, 22)];
    [leftButton setImage:[UIImage imageNamed:@"返回白色"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:leftButton];
    //    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    
    self.personView = [[FPRegisterSelectView alloc] init];
    self.personView.backgroundColor = [UIColor whiteColor];
    self.personView.regType = InitRegisterType_Personal;
    [self.personView isSelectWith:YES isPerson:YES];
    
    WeakObj(self);
    self.personView.reBtnSelectBlock = ^{
        selfWeak.registerType = InitRegisterType_Personal;
        [selfWeak.personView isSelectWith:YES isPerson:YES];
        [selfWeak.enterpriseView isSelectWith:NO isPerson:NO];
    };
    [self.view addSubview:self.personView];
    
    [self.personView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.view.mas_centerY).offset(-15);
        make.right.equalTo(self.view.mas_centerX).offset(-20);
        make.width.equalTo(@127);
        make.height.equalTo(@160);
    }];
    
    
    self.enterpriseView = [[FPRegisterSelectView alloc] init];
    self.enterpriseView.backgroundColor = [UIColor whiteColor];
    self.enterpriseView.regType = InitRegisterType_Enterprise;
    [self.enterpriseView isSelectWith:NO isPerson:NO];
    self.enterpriseView.reBtnSelectBlock = ^{
        selfWeak.registerType = InitRegisterType_Enterprise;
        [selfWeak.personView isSelectWith:NO isPerson:YES];
        [selfWeak.enterpriseView isSelectWith:YES isPerson:NO];
    };
    [self.view addSubview:self.enterpriseView];

    [self.enterpriseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.view.mas_centerY).offset(-15);
        make.left.equalTo(self.view.mas_centerX).offset(20);
        make.width.equalTo(@127);
        make.height.equalTo(@160);
    }];

    
    UILabel *desLabel = [[UILabel alloc] init];
    [desLabel setText:@"开启您的私人订制\n选择您的身份类型完成筛选"];
    desLabel.font = [UIFont fontWithName:@"MicrosoftYaHei" size:18];
    desLabel.numberOfLines = 0;
    desLabel.textAlignment = NSTextAlignmentCenter;
    desLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:desLabel];
    
    [desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.enterpriseView.mas_top).offset(-71);
        make.left.equalTo(@40);
        make.right.equalTo(self.view).offset(-40);
    }];
    

    UIButton * sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
    sureButton.layer.masksToBounds = YES;
    sureButton.layer.cornerRadius = 22;
    [sureButton setImage:[UIImage imageNamed:@"打勾红色"] forState:UIControlStateNormal];
    [sureButton addTarget:self action:@selector(sureClick) forControlEvents:UIControlEventTouchUpInside];
    sureButton.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:sureButton];

    [sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(self.enterpriseView.mas_bottom).offset(58);
        make.width.equalTo(@295);
        make.height.equalTo(@44);
    }];
    
}

@end



@interface FPRegisterSelectView ()

@property (nonatomic,strong)  UIImageView * topImageV;
@property (nonatomic,strong)  UIImageView * centerImageV;
@property (nonatomic,strong)  UILabel * textLab;


@end

@implementation FPRegisterSelectView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setViewUI];
    }
    return self;
}


- (void)sureClick{
    if (self.reBtnSelectBlock) {
        self.reBtnSelectBlock();
    }
}

- (void)isSelectWith:(BOOL)selected isPerson:(BOOL)isPreson
{
    self.textLab.text = isPreson == YES ? @"个人" : @"企业";
    if (selected) {
        self.topImageV.hidden = NO;
        self.centerImageV.image = isPreson == YES ? [UIImage imageNamed:@"个人"] : [UIImage imageNamed:@"企业红色"];
        self.textLab.textColor = [UIColor redColor];
    }else{
        self.topImageV.hidden = YES;
        self.centerImageV.image = isPreson == YES ? [UIImage imageNamed:@"个人灰色"] : [UIImage imageNamed:@"企业灰色"];
        self.textLab.textColor = [UIColor grayColor];
    }
}

- (void)setViewUI
{
    self.topImageV  = [[UIImageView alloc] init];
    self.topImageV.image = [UIImage imageNamed:@"组-2"];
    self.topImageV.userInteractionEnabled = YES;
    [self addSubview:self.topImageV];
    
    [self.topImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(@0);
        make.width.height.equalTo(@34);
    }];
    
    self.centerImageV  = [[UIImageView alloc] init];
    self.centerImageV.userInteractionEnabled = YES;
    [self addSubview:self.centerImageV];
    
    [self.centerImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(@40);
        make.width.equalTo(@48);
        make.height.equalTo(@51);
    }];
    
    self.textLab  = [[UILabel alloc] init];
    self.textLab.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.textLab];
    
    [self.textLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.centerImageV.mas_bottom).offset(15);
        make.left.equalTo(@0);
        make.width.equalTo(self);
        make.height.equalTo(@20);
    }];

    
    UIButton * clickBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [clickBtn addTarget:self action:@selector(sureClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:clickBtn];
    
    [clickBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(@0);
        make.width.height.equalTo(self);
    }];
    
}


@end

